package com.gator.desig_mode.responsibilitychain;


/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc
 */
public abstract class Handler {

  protected Handler nextHandler;//下一个处理者

  private String name;

  public Handler(String name) {
    this.name = name;
  }

  //指定下一个处理者
  public void setNextHandler(Handler nextHandler) {
    this.nextHandler = nextHandler;
  }

  //处理请求，子类实现
  public abstract void processorRequest(Request request);
}


class FirstHandler extends Handler {

  public FirstHandler(String name) {
    super(name);
  }

  @Override
  public void processorRequest(Request request) {
    //0 - 500
    if (request.getMoney() < 500 && request.getMoney() > 0) {
      System.out.println("FirstHandler 处理完毕！");
    } else {
      //执行不了调用下一个
      nextHandler.processorRequest(request);
    }

  }
}


class SecondHandler extends Handler {

  public SecondHandler(String name) {
    super(name);
  }

  @Override
  public void processorRequest(Request request) {

    // 500 - 1000
    if (request.getMoney() <= 1000 && request.getMoney() >= 500) {
      System.out.println("SecondHandler 处理完毕！");
    } else {
      //执行不了调用下一个
      nextHandler.processorRequest(request);
    }

  }
}

class LastHandler extends Handler {

  public LastHandler(String name) {
    super(name);
  }

  @Override
  public void processorRequest(Request request) {

    // 1000 <
    if (request.getMoney() > 1000) {
      System.out.println("LastHandler 处理完毕！");
    } else {
      //执行不了调用下一个
      nextHandler.processorRequest(request);
    }

  }
}